package operations;

import book.Book;
import book.Booklist;

import java.util.Scanner;

public class DelOperation implements Operation{
    @Override
    public void work(Booklist booklist) {
        System.out.println("删除图书......");
        Scanner scanner = new Scanner(System.in);

        System.out.println("请选择你要删除的图书：");
        String name = scanner.nextLine();

        int i;
        int j;
        for (i=0 ; i < booklist.getUesdSize(); i++){
            if (booklist.getBook(i).getName().equals(name)){
                break;
            }
        }
        if (i == booklist.getUesdSize()){
            System.out.println("没有你要删除的书");
        }
        for ( j = i+1 ;j < booklist.getUesdSize()-1;j++){
            Book book = booklist.getBook(j);
            booklist.setBook(i,book);
        }
        booklist.setUesdSize(j);
        booklist.setBook(j,null);
        System.out.println("删除成功！！！");
    }
}
